const app = getApp()
const globalUrl = app.globalData.globalUrl
const img = app.globalData.img

var end;
var begin;
var pageIndex = 1;

Page({

  /**
   * 页面的初始数据
   */
  data: {
    StatusBar: app.globalData.StatusBar,
    CustomBar: app.globalData.CustomBar,
    avata: '',
    records:[],
    hasMore: true
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.setNavigationBarColor({
      frontColor: '#ffffff',
      backgroundColor: '#3aadfe',
      animation: {
        duration: 0,
        timingFunc: 'linear'
      }
    })
    // this.getData()
  },
  loadMore(){
    this.getData()
  },
  getData(){
    wx.request({
      url: globalUrl + 'passenger/getExpensesRecord',
      method: 'POST',
      header: app.globalData.header,
      data: {
        "indexPageNum": pageIndex,
        "order": true,
        "size": 10,
        "sortFieldNames": [
          "createtime"
        ]
      },
      success: res => {
        var records = res.data.resultParm.expenses
        if (records.length > 0) {
          pageIndex++
          this.setData({
            records: this.data.records.concat(records),
            hasMore: true
          })
        }else{
          this.setData({
            hasMore: false
          })
        }
        if(records.length > 0 && records.length < 10 && pageIndex == 2){
          this.setData({
            hasMore: false
          })
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    pageIndex = 1
    this.getData()
  },
  onHide(){
    this.setData({
      records:[],
      hasMore: true
    })
  }
})